package com.itheima.controller;

import com.itheima.manager.PmsProductManager;
import com.itheima.util.R;
import com.itheima.vo.PmsCreateProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping
public class PmsProductController {
    @Autowired
    PmsProductManager pmsProductManager;

    @GetMapping("/product/list")
    public R findAllByPage(
            @RequestParam(required = false)Integer brandId,
            @RequestParam(required = false)String keyword,
            @RequestParam(defaultValue = "1")Integer pageNum,
            @RequestParam(defaultValue = "5")Integer pageSize,
            @RequestParam(required = false)Integer productCategoryId,
            @RequestParam(required = false)Integer productSn,
            @RequestParam(required = false)Integer publishStatus,
            @RequestParam(required = false)Integer verifyStatus
    ){

        return pmsProductManager.findAllByPage(brandId,keyword,pageNum,pageSize,productCategoryId,productSn,publishStatus,verifyStatus);
    }

    @PostMapping("/product/create")
    public R createProduct(@RequestBody PmsCreateProductVo pmsCreateProductVo){
       pmsProductManager.createProduct(pmsCreateProductVo);
       return R.success("添加成功");
    }

    //根据商品id获取商品编辑信息
    @GetMapping("/product/updateInfo/{id}")
    public R getInfoById(@PathVariable(value = "id") Integer id){
       return R.success( pmsProductManager.findProductInfoById(id));
    }

    //批量上下架商品
    @PostMapping("/product/update/publishStatus")
    public R outProductByIds(
            @RequestParam(value = "ids")List<Integer>ids,
            @RequestParam (value = "publishStatus" )Integer publishStatus
            ){
        pmsProductManager.outProductByIds(ids,publishStatus);
        return R.success(null);
    }
    //批量推荐/取消推荐商品
    @PostMapping("/product/update/recommendStatus")
    public R pushProductByIds(
            @RequestParam(value = "ids")List<Integer>ids,
            @RequestParam (value = "recommendStatus" )Integer recommendStatus
    ){
        pmsProductManager.pushProductByIds(ids,recommendStatus);
        return R.success(null);
    }
    //批量推荐/取消推荐商品
    @PostMapping("/product/update/newStatus")
    public R newProductByIds(
            @RequestParam(value = "ids")List<Integer>ids,
            @RequestParam (value = "newStatus" )Integer newStatus
    ){
        pmsProductManager.newProductByIds(ids,newStatus);
        return R.success(null);
    }
    //批量修改删除状态
    @PostMapping("/product/update/deleteStatus")
    public R changeDeleteStatusProductByIds(
            @RequestParam(value = "ids")List<Integer>ids,
            @RequestParam (value = "deleteStatus" )Integer deleteStatus
    ){
        pmsProductManager.changeDeleteStatusProductByIds(ids,deleteStatus);
        return R.success(null);
    }


    @PostMapping("/product/update/{id}")
    public R updateProduct(@PathVariable(value = "id")Integer id,
                           @RequestBody PmsCreateProductVo pmsCreateProductVo
                           )
    {
        pmsProductManager.updateProduct(id,pmsCreateProductVo);
        return R.success(null);
    }



}
